<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>手机号码验证工具</title>
    <script src="https://cdn.jsdelivr.net/npm/libphonenumber-js@1.10.6/bundle/libphonenumber-js.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        
        .container {
            width: 100%;
            max-width: 500px;
            background: rgba(255, 255, 255, 0.9);
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            padding: 30px;
            backdrop-filter: blur(10px);
        }
        
        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
            font-weight: 600;
            position: relative;
        }
        
        h1:after {
            content: '';
            display: block;
            width: 60px;
            height: 4px;
            background: linear-gradient(to right, #6a11cb, #2575fc);
            margin: 10px auto 0;
            border-radius: 2px;
        }
        
        .input-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #444;
        }
        
        select, input {
            width: 100%;
            padding: 14px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        select:focus, input:focus {
            border-color: #6a11cb;
            outline: none;
        }
        
        .validation-result {
            padding: 20px;
            background: #f8f9fa;
            border-radius: 8px;
            margin-top: 30px;
            min-height: 150px;
            border-left: 5px solid #6a11cb;
        }
        
        .result-title {
            font-weight: 600;
            color: #333;
            margin-bottom: 15px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .result-item {
            margin-bottom: 10px;
            display: flex;
        }
        
        .result-label {
            font-weight: 500;
            min-width: 120px;
            color: #555;
        }
        
        .result-value {
            flex: 1;
            word-break: break-word;
        }
        
        .valid {
            color: #28a745;
        }
        
        .invalid {
            color: #dc3545;
        }
        
        .examples {
            margin-top: 25px;
            padding-top: 15px;
            border-top: 1px solid #eee;
        }
        
        .examples h3 {
            margin-bottom: 10px;
            color: #444;
            font-size: 16px;
        }
        
        .example-list {
            list-style-type: none;
            font-size: 14px;
            color: #666;
        }
        
        .example-list li {
            margin-bottom: 5px;
            padding-left: 15px;
            position: relative;
        }
        
        .example-list li:before {
            content: '•';
            position: absolute;
            left: 0;
            color: #6a11cb;
        }
        
        @media (max-width: 600px) {
            .container {
                padding: 20px;
            }
            
            h1 {
                font-size: 24px;
            }
            
            select, input {
                padding: 12px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1><i class="fas fa-mobile-alt"></i> 手机号码验证工具</h1>
        
        <div class="input-group">
            <label for="country"><i class="fas fa-globe"></i> 国家/地区代码</label>
            <select id="country">
                <option value="US">美国 (+1)</option>
                <option value="GB">英国 (+44)</option>
                <option value="DE">德国 (+49)</option>
                <option value="FR">法国 (+33)</option>
                <option value="CN" selected>中国 (+86)</option>
                <option value="JP">日本 (+81)</option>
                <option value="KR">韩国 (+82)</option>
                <option value="IN">印度 (+91)</option>
                <option value="BR">巴西 (+55)</option>
                <option value="RU">俄罗斯 (+7)</option>
            </select>
        </div>
        
        <div class="input-group">
            <label for="phone"><i class="fas fa-phone"></i> 手机号码</label>
            <input type="text" id="phone" placeholder="输入手机号码（不含国家代码）" autocomplete="off">
        </div>
        
        <div class="validation-result">
            <div class="result-title"><i class="fas fa-clipboard-check"></i> 验证结果</div>
            <div class="result-item">
                <span class="result-label">有效性：</span>
                <span class="result-value" id="validity">-</span>
            </div>
            <div class="result-item">
                <span class="result-label">国际格式：</span>
                <span class="result-value" id="international">-</span>
            </div>
            <div class="result-item">
                <span class="result-label">国家代码：</span>
                <span class="result-value" id="countryCode">-</span>
            </div>
            <div class="result-item">
                <span class="result-label">运营商：</span>
                <span class="result-value" id="carrier">-</span>
            </div>
        </div>
        
        <div class="examples">
            <h3><i class="fas fa-lightbulb"></i> 示例号码</h3>
            <ul class="example-list">
                <li>中国: 13800138000, 13912345678</li>
                <li>美国: 2025550126, 4155550130</li>
                <li>英国: 7400123456, 7911123456</li>
            </ul>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const countrySelect = document.getElementById('country');
            const phoneInput = document.getElementById('phone');
            const validityEl = document.getElementById('validity');
            const internationalEl = document.getElementById('international');
            const countryCodeEl = document.getElementById('countryCode');
            const carrierEl = document.getElementById('carrier');
            
            // 初始示例号码
            phoneInput.value = '13800138000';
            validatePhoneNumber();
            
            // 监听输入变化
            countrySelect.addEventListener('change', validatePhoneNumber);
            phoneInput.addEventListener('input', validatePhoneNumber);
            
            function validatePhoneNumber() {
                const countryCode = countrySelect.value;
                const phoneNumber = phoneInput.value.trim();
                
                // 清除之前的结果
                validityEl.textContent = '-';
                validityEl.className = 'result-value';
                internationalEl.textContent = '-';
                countryCodeEl.textContent = '-';
                carrierEl.textContent = '-';
                
                if (!phoneNumber) {
                    return;
                }
                
                try {
                    // 使用 libphonenumber-js 解析和验证号码
                    const parsedNumber = libphonenumber.parse(phoneNumber, countryCode);
                    
                    if (!parsedNumber.phone) {
                        throw new Error('无效号码');
                    }
                    
                    const isValid = libphonenumber.isValidNumber(parsedNumber);
                    const internationalFormat = libphonenumber.formatNumber(parsedNumber, 'INTERNATIONAL');
                    const nationalFormat = libphonenumber.formatNumber(parsedNumber, 'NATIONAL');
                    const countryCallingCode = parsedNumber.countryCallingCode;
                    
                    // 显示验证结果
                    validityEl.textContent = isValid ? '有效号码' : '无效号码';
                    validityEl.classList.add(isValid ? 'valid' : 'invalid');
                    internationalEl.textContent = internationalFormat;
                    countryCodeEl.textContent = `+${countryCallingCode}`;
                    
                    // 尝试获取运营商信息（在某些国家可用）
                    try {
                        const carrierInfo = libphonenumber.getNumberType(parsedNumber);
                        carrierEl.textContent = getCarrierName(carrierInfo);
                    } catch (e) {
                        carrierEl.textContent = '未知';
                    }
                    
                } catch (error) {
                    validityEl.textContent = '无效号码';
                    validityEl.classList.add('invalid');
                    internationalEl.textContent = '格式错误';
                }
            }
            
            function getCarrierName(type) {
                const types = {
                    'FIXED_LINE': '固定电话',
                    'MOBILE': '移动电话',
                    'FIXED_LINE_OR_MOBILE': '固定或移动电话',
                    'TOLL_FREE': '免费电话',
                    'PREMIUM_RATE': ' premium rate',
                    'SHARED_COST': '共享成本',
                    'VOIP': '网络电话',
                    'PERSONAL_NUMBER': '个人号码',
                    'PAGER': '寻呼机',
                    'UAN': '通用接入号码',
                    'VOICEMAIL': '语音邮件',
                    'UNKNOWN': '未知类型'
                };
                
                return types[type] || '未知类型';
            }
        });
    </script>
</body>
</html>